package cn.codewen.service.impl;

import cn.codewen.dao.impl.UserDaoImpl;
import cn.codewen.pojo.User;
import cn.codewen.service.UserService;

public class UserServiceImpl implements UserService {
    @Override
    public User checkUser(String username, String password) {

        //1. 通过用户名找到对应的用户
        UserDaoImpl userDao = new UserDaoImpl();
        //2. 调用userDao的getOneByUsername
        User user = userDao.getByOneUsername(username);
        //3. 判断这个用户是否存在,并且判断密码是否正确
        if (user!=null && user.getPassword().equals(password)){
            //用户验证通过
            return  user;


        }else {

            return null;
        }



    }

    @Override
    public Boolean regUser(User user) {
        //1. 创建userDao对象
        UserDaoImpl userDao = new UserDaoImpl();
        //2.调用方法
        User rs = userDao.insert(user);
        //3. 判断
        if (rs!=null){
            return  true;
        }else {
            return  false;
        }

    }
}
